#pragma once
#include <iostream>
#include <string>
#include <functional>
#include "Log.hpp"
class Reactor;
class Connection;
using handler_t = function<string(string &)>;
class Connection
{
public:
    Connection()
        : _events(0), _owner(nullptr)
    {
    }
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    virtual int GetFd() = 0;
    void SetEvents(const uint32_t &events)
    {
        _events = events;
    }
    uint32_t GetEvents()
    {
        return _events;
    }
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    Reactor* GetOwner()
    {
        return _owner;
    }
    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }
    ~Connection() {}

private:
    // 关心事件
    uint32_t _events;

    // 回指指针
    Reactor *_owner;

public:
    handler_t _handler; // 基类中定义了一个回调函数
};
